#ifndef _SENDBUFFER_H_
#define _SENDBUFFER_H_

#include <windows.h>
#include "util_buffer.h"

//=============================================================================================================================
//=============================================================================================================================
class SendBuffer
{
public:
	SendBuffer()			{ m_bComplete = TRUE; }
	virtual ~SendBuffer()	{}

	inline VOID Clear()
	{
		m_RingBuffer.clear(); 
		m_bComplete = TRUE; 
	}

	inline VOID Completion( int nBytesSend ) 
	{ 
		m_RingBuffer.drop_front(nBytesSend );
		m_bComplete = TRUE; 
	}

	inline BOOL	GetSendParam( BYTE **ppSendPtr, int &nLength ) 
	{
		if( !IsReadyToSend() ) { nLength = 0; return FALSE; }
		*ppSendPtr	= m_RingBuffer.fragment_ptr();
		nLength		= m_RingBuffer.fragment_len();
		m_bComplete = FALSE;
		return TRUE; 
	}

	inline BOOL Write( BYTE *pMsg, WORD wSize )
	{
		if( XR_FAILED(m_RingBuffer.insert_back( pMsg, wSize )) )
		{
			return FALSE;
		}
		else
		{
			return TRUE; 
		}
	}

	inline DWORD GetLength() { return m_RingBuffer.length(); }

private:
	inline BOOL			IsReadyToSend() { return ( m_bComplete && m_RingBuffer.length() > 0 ) ? TRUE : FALSE; }

private:
	BOOL				m_bComplete;
	RingBuffer_t		m_RingBuffer;
};

#endif
